package com.xframe.domain.repository;

import com.xframe.domain.knowledgeBase.CommentsReply;
import com.xframe.domain.knowledgeBase.KnowledgeBase;
import com.xframe.domain.knowledgeBase.KnowledgeComments;
import com.xframe.domain.knowledgeBase.KnowledgeFiles;
import com.xframe.xdal.core.exception.DalFrameException;
import com.xframe.xdal.core.model.ConditionValue;
import com.xframe.xdal.core.model.ConditionValueCollection;
import com.xframe.xdal.core.model.IModel;
import com.xframe.xdal.core.model.mapping.ITableInfo;
import com.xframe.xdal.core.model.mapping.TableInfoBuilder;
import com.xframe.xdal.core.tran.XTransaction;

public class KnowledgeCommentsRepository extends SysBaseRepository{
    @XTransaction
    @Override
    public Integer delete(IModel model, ITableInfo tableInfo) throws DalFrameException {

        try {
            if(model instanceof KnowledgeComments){
                KnowledgeComments knowledgeComments= (KnowledgeComments)model;

                ConditionValueCollection conditionValueCollection = new ConditionValueCollection();
                conditionValueCollection.add(new ConditionValue("commentId",knowledgeComments.getCommentId()));
                defDataBaseAccess.deleteMany(TableInfoBuilder.BuildTableInfoByAnnotation(CommentsReply.class),conditionValueCollection);
                defDataBaseAccess.delete(knowledgeComments);
                return 1;
            }
            return 0;
        } catch (DalFrameException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            throw e;
        }
    }
}
